﻿using HighThroughput.ShareData;
using OSSUtility;
using Ozone.Help;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Ozone.Views.Widget
{
    /// <summary>
    /// UCRealDataGrid.xaml 的交互逻辑
    /// </summary>
    public partial class UCRealDataGrid : UserControl
    {

        List<RealDataItem> lstRealData = new List<RealDataItem>();

        public UCRealDataGrid()
        {
            InitializeComponent();

            Init();
        }

        public void Star()
        {
            RefreshRealDataThread();
        }

        public void Stop()
        {
            bRefreshRealDataFlag = false;
        }


        private void Init()
        {
            lstRealData.Add(new RealDataItem() { FName = "原料泵",FValue="0",FUnit="mL/min" });
            lstRealData.Add(new RealDataItem() { FName = "还原剂", FValue = "0", FUnit = "mL/min" });
            lstRealData.Add(new RealDataItem() { FName = "背压阀", FValue = "0", FUnit = "MPa" });
            lstRealData.Add(new RealDataItem() { FName = "气体流量", FValue = "0", FUnit = "mL/min" });
            lstRealData.Add(new RealDataItem() { FName = "臭氧入口", FValue = "0", FUnit = "mg/L" });
            lstRealData.Add(new RealDataItem() { FName = "臭氧出口", FValue = "0", FUnit = "mg/L" });
            lstRealData.Add(new RealDataItem() { FName = "反应器温度", FValue = "0", FUnit = "℃" });


            dgRealData.ItemsSource = null;
            dgRealData.ItemsSource = lstRealData;
        }

        //刷新实时数据
        private void RefreshRealDataView()
        {
            try
            {
               
               

            }
            catch (Exception ex)
            {
            }
        }


        //刷新实时数据线程
        bool bRefreshRealDataFlag = false;
        private void RefreshRealDataThread()
        {
            bRefreshRealDataFlag = true;

            Task.Run(() =>
            {
                while (bRefreshRealDataFlag)
                {
                    this.Dispatcher.Invoke(new Action(
                        delegate
                        {
                            try
                            {
                                Utility.Delay(1000);
                                RefreshRealDataView();
                            }
                            catch (Exception ex)
                            {

                            }
                        }
                        )
                    );
                }
            });

        }
    }


    public class RealDataItem
    {
        public string FName { set; get; }
        public string FValue { set; get; }

        public string FUnit { set; get; }

    }
}
